package com.wsoft.system.controller;

import com.github.pagehelper.PageInfo;
import com.wsoft.response.ResponsePage;
import com.wsoft.response.ResponseResult;
import com.wsoft.system.dto.TsMutiLangDto;
import com.wsoft.system.entity.TsMutiLangEntity;
import com.wsoft.system.query.lang.TsMutiLangReq;
import com.wsoft.system.service.ITsMutiLangService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author juiet
 * @since 2024年08月25日 20:05:01
 */
@RestController
@Tag(name = "多语言控制控制器")
@RequestMapping("/ts/lang")
public class TsMutiLangController {

    @Autowired
    private ITsMutiLangService tsMutiLangService;

    @Operation(summary = "多语言列表(分页)",description = "分页")
    @PostMapping("/list")
    public ResponseResult page(@RequestBody @Valid TsMutiLangReq req) {
        PageInfo<TsMutiLangEntity> pageInfo = tsMutiLangService.pageMutiLang(req);
        return ResponseResult.success(ResponsePage.restPage(pageInfo));
    }

    @Operation(summary = "新增多语言",description = "新增多语言")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody @Valid TsMutiLangDto dto) {
        boolean b = tsMutiLangService.insert(dto);
        if (b){
            return ResponseResult.success("[sys.msg.success]");
        }
        else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "修改多语言",description = "修改多语言")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody @Valid TsMutiLangDto dto) {
        boolean b = tsMutiLangService.update(dto);
        if (b){
            return ResponseResult.success("[sys.msg.success]");
        }
        else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }
    @Operation(summary = "删除多语言",description = "删除多语言")
    @ApiResponse(responseCode = "200", description = "OK")
    @GetMapping("/delete")
    public ResponseResult delete(@RequestParam("id") Long id) {
        boolean b = tsMutiLangService.delete(id);
        if (b){
            return ResponseResult.success("[sys.msg.success]");
        }
        else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }
}
